package com.itheima.itheima_health.controller.user;

import com.itheima.itheima_health.constant.MessageConstant;
import com.itheima.itheima_health.entity.Result;
import com.itheima.itheima_health.pojo.Login;
import com.itheima.itheima_health.pojo.User;
import com.itheima.itheima_health.service.UserLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户登录相关接口
 */
@RestController
@RequestMapping("/user/login")
@Slf4j
@Api(tags = "用户登录相关接口")
public class LoginController {
    @Autowired
    private UserLoginService userLoginService;
    /*@Autowired
    private JwtProperties jwtProperties;*/
    @PostMapping("/check")
    @ApiOperation("用户登录")
    public Result Login(@RequestBody Login loginInfo){
        log.info("邮箱登录:{}",loginInfo);
        User user = userLoginService.userlogin(loginInfo);

        /*//登录成功后，生成jwt令牌
        Map<String, Object> claims = new HashMap<>();
        claims.put(JwtClaimsConstant.USER_ID, user.getId());
        String token = JwtUtil.createJWT(
                jwtProperties.getUserSecretKey(),
                jwtProperties.getUserTtl(),
                claims);
        log.info("jwt令牌:{}",token);
        user.setToken(token);*/

        return new Result(true, MessageConstant.LOGIN_SUCCESS,user);
    }
}
